package com.stu.wgt.test.service.Imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.stu.wgt.test.bean.Shipment;
import com.stu.wgt.test.mapper.ShipmentMapper;
import com.stu.wgt.test.service.ShipmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wgt
 * @since 2024-02-04
 */
@Service
public class ShipmentServiceImpl extends ServiceImpl<ShipmentMapper, Shipment> implements ShipmentService {

    @Autowired
    ShipmentMapper shipmentMapper;

    @Override
    public int insert(Shipment shipment) {
        return shipmentMapper.insert(shipment);
    }

    @Override
    public int delete(int id) {
        return shipmentMapper.deleteById(id);
    }

    @Override
    public int update(Shipment shipment) {
        QueryWrapper<Shipment> qw = new QueryWrapper<>();
        qw.eq("id", shipment.getId());
        return shipmentMapper.update(shipment, qw);
    }

    @Override
    public List<Shipment> selectAllShipment() {
        return shipmentMapper.selectList(null);
    }

    @Override
    public List<Shipment> selectById(int id) {
        QueryWrapper<Shipment> qw = new QueryWrapper<>();
        qw.eq("id", id);
        return shipmentMapper.selectList(qw);
    }

    @Override
    public List<Shipment> selectByName(String username) {
        return null;
    }

    @Override
    public IPage<Shipment> searchShipment(String query, int pageNum, int pageSize) {
        Page<Shipment> page = new Page<>(pageNum, pageSize);
        QueryWrapper<Shipment> qw = new QueryWrapper<>();
        qw.like("name", query);
        return shipmentMapper.selectPage(page, qw);
    }

    @Override
    public List<Shipment> selectByTrackNumber(String trickNumber) {
        QueryWrapper<Shipment> qw = new QueryWrapper<>();
        qw.eq("tracking_number", trickNumber);
        return shipmentMapper.selectList(qw);
    }

}
